package com.fz;

import com.sun.imageio.plugins.common.ImageUtil;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * Created by Administrator on 2017/5/4.
 */
//水印文字效果
// 就是图片上添加文字版权信息
    //掉的方法
public class Test {

    /*public static void main(String[] args) {*/
     /*往整个文件夹里面加水印，直接在test中执行*/
       /*   ImgUtil iu = new ImgUtil();
        Color c = iu.getColor文字(0,200,0,150);
        File f = new File("d:/ggg");//文件夹的名字
        File[] fs = f.listFiles();
        for(File ft : fs) {
            if(ft.isFile() && ft.getName().endsWith(".jpg")) {
                iu.text(ft.getPath(), "老白在看你", c, 50, 0);
            }
        }
    }*/
       /*掉的imgUtil里面的test方法 */
   /* ImgUtil iu = new ImgUtil();
        Color c = iu.getColor(0,0,255,150);
        File f = new File("c:/ggg");
        File[] fs = f.listFiles();
        for(File ft : fs) {
            if(ft.isFile() && ft.getName().endsWith(".jpg")) {
                iu.text(ft.getPath(), "联系电话：1242423423", c, 50, 0);//在这里掉的方法
            }
        }*/


        //水印图标效果 掉的方法
   /*public static void main(String[] args) {
        ImgUtil iu = new ImgUtil();
        iu.logo("c:/p.jpg","c:/logo.png",0);//这行是掉的方法加给logo所在的位置
    }*/
        //水印图标效果
  /*  public static void main(String[] args) {
        String img = "c:/p.jpg";
        String logo = "c:/logo.png";
        try{
            BufferedImage i = ImageIO.read(new File(img));
             BufferedImage li = ImageIO.read(new File(logo));
            Graphics2D g = (Graphics2D)i.getGraphics();
            g.drawImage(li,10,10,null);
            ImageIO.write(i,"jpeg",new File(img));
            g.dispose();
        }catch (Exception e){

        }
    }
*/
        //缩略图效果
  /*  public static void main(String[] args) {
        String img = "c:/g.jpg";//原图
        int w = 200;//把原图改为宽200
        int h = 300;//把原图改为高300
        BufferedImage ii = new BufferedImage(w,h,1); //建立一个图像,尺寸为200*300
        try{
            BufferedImage i = ImageIO.read(new File(img));
            Graphics2D g = (Graphics2D)ii.getGraphics();
            //将图像i 按比较缩小写到 上边建立的图像上
            g.drawImage(i,0,0,w,h,0,0,i.getWidth(),i.getHeight(),null);
            //保存建立的图像
            ImageIO.write(ii,"jpeg",new File("c:/g200_300.jpg"));
            g.dispose();
        }catch(Exception e){

        }

    }
*/

        //缩略图效果
   /* public static void main(String[] args) {
        String img = "c:/g.jpg";
        int w = 50;
        int h = 50;

        try{
            BufferedImage i = ImageIO.read(new File(img));
            int ww = i.getWidth();
            int hh = i.getHeight();
            // 按比例
            //double d = .5;
            //w = (int)(ww*d);
            //h = (int)(hh*d);

                 w = 100;
                //高按宽比例来完成
                h = (int)(hh * ((double)w/ww));

            BufferedImage ii = new BufferedImage(w,h,1); //建立一个图像
            Graphics2D g = (Graphics2D)ii.getGraphics();
            g.drawImage(i,0,0,w,h,0,0,ww,hh,null);
            ImageIO.write(ii,"jpeg",new File("c:/girl5.jpg"));
            g.dispose();
        }catch(Exception e){

        }
    }*/
   /* 剪切图片*/
   /* public static void main(String[] args) {
         String img = "c:/p.jpg";
         try{
             BufferedImage i = ImageIO.read(new File(img));
             BufferedImage newimg = new BufferedImage(280,280,1);//设定的画布，一定要和新图设定的宽高一样
                Graphics2D g = (Graphics2D)newimg.getGraphics();
             g.drawImage(i,0,0,280,280,10,10,20+280,0+280,null);
            /*//*(i,新图起始x,,新图起始y,新图设定的宽，新图设定的高，老图截取开始x位置，老图截取开始y位置,老图截取的宽，老图截取的高)*//**//*
             ImageIO.write(newimg,"jpeg",new File("c:/p2.jpg"));
             g.dispose();
         }catch (Exception e){
             e.printStackTrace();
         }

     }*/
   /* 剪切图片掉的方法*/
    /* public static void main(String[] args){
            try {

                String img = "c:/p.jpg";
                BufferedImage i = ImageIO.read(new File(img));
                int w = 200;
                int h = 200;
                BufferedImage b = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
                Graphics2D g = (Graphics2D) b.getGraphics();
                int x = 100;
                int y = 100;
                g.drawImage(image, 0, 0, w, h, x, y, w + x, h + y, null);
                ImageIO.write(b, "jpeg", new File("c:/p2.jpg"));
                g.dispose();

            } catch (IOException e) {
                e.printStackTrace();
            }


        }*/

    }

